package com.aistar.mapper;

import com.aistar.model.entity.Resume;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ResumeMapper {

    // 根据id获取简历
    @Select("select * from resume where id = #{id}")
    Resume findById(Integer id);

    // 获取所有简历
    @Select("select * from resume where status=1 and privacy=1")
    List<Resume> findAll();

    // 获取简历limit(m,n) m+行开始的n行
    @Select("select * from resume where status=1 and privacy=1 limit #{upper},#{limit}")
    List<Resume> findByPage(int upper, int limit);

    //根据简历状态获取简历
    @Select("select * from resume where status = 1 and privacy=1")
    List<Resume> findByStatus();

    //更新简历信息
    @Update("update resume set name=#{name},sex=#{sex},res_identity=#{resIdentity},birthday=#{birthday},area=#{area},phone=#{phone},email=#{email},expect_industry=#{expectIndustry},expect_job=#{expectJob},expect_city=#{expectCity},salary_requirement=#{salaryRequirement},res_state=#{resState},summary=#{summary},resume_avatar=#{resumeAvatar},url=#{url},work_year=#{workYear},update_time=#{updateTime},frequency=#{frequency},employee_id=#{employeeId},status=#{status},privacy=#{privacy} where id=#{id}")
    Integer updateResume(Resume resume);

    //添加简历信息
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into resume(name,sex,res_identity,birthday,area,phone,email,expect_industry,expect_job,expect_city,salary_requirement,res_state,summary,resume_avatar,url,work_year,update_time,frequency,employee_id,status,privacy) values(#{name},#{sex},#{resIdentity},#{birthday},#{area},#{phone},#{email},#{expectIndustry},#{expectJob},#{expectCity},#{salaryRequirement},#{resState},#{summary},#{resumeAvatar},#{url},#{workYear},#{updateTime},#{frequency},#{employeeId},#{status},#{privacy})")
    Integer insertResume(Resume resume);

    //根据简历id获取求职者id
    @Select("select employee_id from resume where id = #{id} and status = 1")
    Integer findEmployeeIdById(Integer id);

    //根据求职者id获取简历
    @Select("select * from resume where employee_id = #{employeeId} and status = 1")
    List<Resume> findByEmployeeId(Integer employeeId);

    // 根据简历id修改简历浏览次数
    @Update("update resume set frequency = frequency+1 where id = #{id}")
    int updateFrequency(Integer id);
    //刷新简历
    @Update("update resume set update_time =#{updateTime} where id = #{id}")
    Integer updateUpdateTimeById(Resume resume);
    //根据简历id和求职者id获取信息
    @Select("select * from resume where id=#{id} and employee_id=#{eid}")
    Resume findByRidAndEid(Integer id,Integer eid);

    //根据简历id获取建立连接
    @Select("select resume_avatar from resume where id=#{id}")
    String findByIdToAvatar(Integer id);

    //删除简历
    @Update("update resume set status=0 where id = #{id}")
    Integer updateResumeById(Integer id);

    // 根据求职者id获取所有的简历id[包括私有的和删除的]
    @Select("select id from resume where employee_id = #{employeeId}")
    List<Integer> findResumeIdByEmployeeId(Integer employeeId);

    //根据简历id修改简历privacy
    @Update("update resume set privacy=#{privacy}  where id = #{id}")
    Integer updatePrivacyById(Resume resume);
}
